/*
 *  Copyright 2012 yura.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.odg.m_ui;

import java.awt.Color;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JList;
import org.opu.odg.dg.question.CustomContentQuestion;
import org.opu.odg.dg.question.Question;
import org.opu.odg.dg.question.TextQuestion;

/**
 *
 * @author yura
 */
public class QuestionListCellRenderer extends DefaultListCellRenderer {

    private static final ImageIcon VAR_ICON = new ImageIcon(
            TreeCellRendererImpl.class.getResource("dolar-16.png"));
    private static final ImageIcon CONTENT_ICON = new ImageIcon(
            TreeCellRendererImpl.class.getResource("grille-16.png"));

    @Override
    public Component getListCellRendererComponent(JList list, Object value, 
            int index, boolean isSelected, boolean cellHasFocus) {
        Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        if (value instanceof Question && ((Question)value).getQuestionAnswer() == null) {
            setForeground(Color.RED);
        }

        if (value instanceof TextQuestion) {
            setIcon(VAR_ICON);
        } else if (value instanceof CustomContentQuestion) {
            setIcon(CONTENT_ICON);
        }

        return component;
    }

}
